package com.lightjet.macross.base.upms.controller;

import com.lightjet.macross.base.feign.api.controller.PrincipalController;
import com.lightjet.macross.base.feign.api.domain.AuthUser;
import com.lightjet.macross.base.upms.service.LoginAdapterService;
import com.lightjet.macross.common.dto.ResponseDTO;
import com.lightjet.macross.common.util.RespUtil;
import com.lightjet.macross.common.util.SpringUtil;
import io.netty.util.internal.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/uniuser")
@Scope("request")
@Log
@RefreshScope
@Api(tags="通用系统权限管理-通用用户体系相关接口集")
public class UniformUserController extends PrincipalController {

    @Value("${biz.usersystembeanname:macross}")
    private String usersystembeanname;

    @RequestMapping(value = "/page", method = {RequestMethod.POST, RequestMethod.GET})
    //@Override
    @ApiOperation(value = "通用用户分页数据接口", notes = "根据关键字筛选条件获取分页的通用用户信息集合")

    public ResponseDTO<Page<AuthUser>> GetUsersPagedByFilters(
            @ApiParam(name="keywords",value = "用户关键字") String keywords,
            @ApiParam(name="usibn",value = "用户体系标识，为空使用平台默认") String usibn,
            @ApiParam(name="pageSize",value = "分页大小") Integer pageSize,
            @ApiParam(name="pageNumber",value = "分页索引") Integer pageNumber) {
        pageSize = pageSize==null?20:pageSize;
        pageNumber = pageNumber == null ? 0: pageNumber;
        Pageable pageable = PageRequest.of(pageNumber, pageSize);
        keywords = StringUtil.isNullOrEmpty(keywords)?"": keywords;
        usibn = StringUtil.isNullOrEmpty(usibn) ? usersystembeanname:usibn;
        LoginAdapterService loginAdapterService = SpringUtil.getBean(usibn,LoginAdapterService.class);
        return RespUtil.CreateOK(loginAdapterService.FindByFilters(keywords,pageable));
    }

}
